﻿using System.Linq;
using System.Web.Mvc;
using System.Data.Entity;
using WeProjectsModel;
using WeProjects.Filters;
using WeProjects.Models;
using WeProjects.Helps;

namespace WeProjects.Controllers
{
    [InitializeSimpleMembership]
    public class HomeController : Controller
    {
        private ProjectsDBEntities db = new ProjectsDBEntities();

        public ActionResult Index()
        {
            //var news = db.News.Include(n => n.Project).Where(n => n.isPublic == 1).Where(n => n.isPublish == 1);//普通
            //ViewBag.noticeLst = db.Notices.ToList();
            HomeVModel model = new HomeVModel();
            model.News = db.News.Where(n => n.isPublic == 1 && n.isPublish == 1).ToList()
                .Select(n => n.ToNewsViewModel()).ToList();
            model.Notices = db.Notices.ToList();
            model.Projects = db.Projects.Where(p=>p.ParentID!=null).ToList().Select(p => p.ToProjectViewMode()).ToList();
            model.Resources = db.Resources.ToList();
            return View(model);
        }
        
        public ActionResult About()
        {
            ViewBag.Message = "Your app description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}
